package com.zy.fee.roadpark.activity.np;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.zy.fee.roadpark.R;
import com.zy.fee.roadpark.fragment.LeaveApplyFragment;
import com.zy.fee.roadpark.fragment.LeaveApplyNotFragment;
import com.zygk.library.base.BaseActivity;
import java.util.ArrayList;
import java.util.List;

public class LeaveApplyActivity extends BaseActivity {
  @BindView(R.id.ll_back) LinearLayout llBack;
  @BindView(R.id.lh_tv_title) TextView lhTvTitle;
  @BindView(R.id.tab) TabLayout tab;
  @BindView(R.id.vp) ViewPager vp;

  private LeaveApplyFragment leaveApplyFragment;
  private LeaveApplyNotFragment leaveApplyNotFragment;
  private MyPagerAdapter myPagerAdapter;

  @Override
  public void setContentView() {
    setContentView(R.layout.activity_leave_apply);
  }

  @Override
  public void init() {
    initData();
    initView();
    initListener();
  }

  private void initData() {
    myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
    vp.setAdapter(myPagerAdapter);
    vp.setOffscreenPageLimit(2);
    tab.setupWithViewPager(vp);
  }

  private void initView() {
    lhTvTitle.setText("申请驶离记录");

  }

  private void initListener() {
    vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

      }

      @Override public void onPageSelected(int position) {
        vp.setCurrentItem(position);
      }

      @Override public void onPageScrollStateChanged(int state) {

      }
    });
  }

  class MyPagerAdapter extends FragmentPagerAdapter {
    private String[] titles = new String[]{"未处理", "已处理"};
    private List<Fragment> fragmentList;

    public MyPagerAdapter(FragmentManager fm) {
      super(fm);

      leaveApplyNotFragment = new LeaveApplyNotFragment();
      leaveApplyFragment = new LeaveApplyFragment();

      fragmentList = new ArrayList<>();
      fragmentList.add(leaveApplyNotFragment);
      fragmentList.add(leaveApplyFragment);
    }

    @Override
    public Fragment getItem(int position) {
      return fragmentList.get(position);
    }

    @Override
    public int getCount() {
      return fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {

      return titles[position];
    }
  }

  @OnClick({ R.id.ll_back }) public void Onclick(View v) {
    switch (v.getId()) {
      case R.id.ll_back:
        this.finish();
        break;
    }
  }
}
